package annuaire.rmi.remotedObject.impl;

import java.io.Serializable;
import java.rmi.RemoteException;

import annuaire.beans.Student;
import annuaire.exceptions.BusinessException;
import annuaire.exceptions.DaoException;
import annuaire.rmi.remotedObject.IStudentService;

/**
 * Classe d'objet distant RMI, servant à gérer les services etudiants.
 * 
 * @author Yannick Lorenzati & Stephanie Malakian
 * 
 */
public class StudentImpl extends RemotedUserImpl implements IStudentService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8686465989808909386L;

	/**
	 * @throws RemoteException
	 */
	public StudentImpl() throws RemoteException {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see rmi.remotedObject.IStudentService#updateStudent(beans.Student)
	 */
	@Override
	public Student updateStudent(Student s) throws Exception {
		try {

			if (s == null) {
				return null;
			}

			s = dao.updateStudent(s);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new BusinessException(e);
		}

		return s;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see annuaire.rmi.remotedObject.impl.RemotedUserImpl#updateBeans(java.io.
	 * Serializable)
	 */
	@Override
	public void updateBeans(Serializable newBeans) throws Exception {

		if (!(newBeans instanceof Student)) {
			throw new BusinessException(
					"les nouvelles donnees ne sont pas conformes");
		}

		this.setAssociedBean(updateStudent((Student) newBeans));
	}

}
